package com.damon.JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.damon.entity.DVCEntity;
import com.damon.utils.DbUtil;

public class DVCJDBC {
	private static Logger logger = LoggerFactory.getLogger(DVCJDBC.class);
	public static ArrayList<DVCEntity> getDeviceList(){
		String sql = "select config_no,ip,port from wcs_plc_config where is_used='1' and config_type='monitor'";
		Connection connection = DbUtil.getConnection();
		Statement statement = null;
		ResultSet resultSet;
		
		ArrayList<DVCEntity> deviceList = new ArrayList<>();
		try {
			statement = connection.createStatement();
			resultSet = statement.executeQuery(sql);
			while(resultSet.next()) {
				DVCEntity deviceInfo = new DVCEntity();
//				deviceInfo.setId(resultSet.getInt("id"));
				deviceInfo.setDeviceNumber(resultSet.getString("config_no"));
				deviceInfo.setIp(resultSet.getString("ip"));
				deviceInfo.setPort(resultSet.getInt("port"));
				deviceList.add(deviceInfo);
			}
		} catch (SQLException e) {
			logger.error("查询设备表出错！！");
			e.printStackTrace();
		}finally {
			try {
				statement.close();
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return deviceList;
	}
}
